﻿var $ModalDialog;

var ModalDialogResizeTimer;

function CreateModalDialog(heading) {
    $ModalDialog = $("<div class=\"modalOverlay\">&nbsp;</div><div class=\"modalContainer\"><div class=\"modalContent\"><span class=\"modalHeader\">" + heading + "</span><div class=\"modalInnerContent\"><div id=\"spinner1\" class=\"spinner\" style=\"display:none;\">"
                    + "<div><div><img id=\"img-spinner\" src=\"/Content/Images/ajax-loader.gif\" alt=\"Loading...\"/></div></div></div></div></div></div>");

    $(document).bind("ready.ModalDialog", function () { clearTimeout(ModalDialogResizeTimer); ModalDialogResizeTimer = setTimeout(ResizeModalDialog, 100); });
    $(window).bind("resize.ModalDialog", function () { clearTimeout(ModalDialogResizeTimer); ModalDialogResizeTimer = setTimeout(ResizeModalDialog, 100); });
    $('.modalInnerContent').bind("resize.ModalDialog", function () { clearTimeout(ModalDialogResizeTimer); ModalDialogResizeTimer = setTimeout(ResizeModalDialog, 100); });

    return $ModalDialog;
}

function ResizeModalDialog() {
    $(".modalContainer").css("top", ($(window).height() - $(".modalContainer").height()) / 3 + $(window).scrollTop() + "px");
    $(".modalContainer").css("left", ($(window).width() - $(".modalContainer").width()) / 2 + $(window).scrollLeft() + "px");
}

function DestroyModalDialog() {
    $(".modalContainer").remove();
    $(".modalOverlay").remove();
    $(document).unbind(".ModalDialog");
    $(window).unbind(".ModalDialog");
}